<template>
  <div>
    <el-menu
        style="width: 200px;min-height: calc(100vh - 50px)"
        :default-active="path"
        router
        class="el-menu-vertical-demo">
      <el-sub-menu index="1" v-if="user.role === 1">
        <template #title><el-icon><Document/></el-icon>系统管理</template>
        <el-menu-item index="/user"><el-icon><Location/></el-icon>用户管理</el-menu-item>
      </el-sub-menu>
      <el-sub-menu>
        <template #title><el-icon><Document/></el-icon>数据管理</template>
        <el-menu-item index="/coupons"><el-icon><Menu/></el-icon>优惠券管理</el-menu-item>
        <el-menu-item index="/commoditys"><el-icon><Menu/></el-icon>商品管理</el-menu-item>
      </el-sub-menu>

    </el-menu>
  </div>
</template>


<script>

import {Location, Setting, Menu, Document} from '@element-plus/icons'
import request from "@/utils/request";

export default {
  components: {
    Location, Setting, Menu, Document
  },
  name: "Aside",
  data() {
    return {
      user: {},
      path: this.$route.path //设置默认高亮的菜单
    }
  },
  created() {
    let userStr = sessionStorage.getItem("user") || "{}"
    this.user = JSON.parse(userStr)

    // 请求服务器，确认当前登录用户的合法信息
    request.get("/user/" + this.user.id).then(res => {
      if (res.code === '200') {
        this.user = res.data
      }
    })
  }
}

</script>
<style scoped>

</style>